// page/coachs/news/index.js
Page({
  data: {
    isHide: false,
    msg: {
      icon: "/images/icon/nodata.png",
      desc: "暂无数据"
    },
    page: 1,
    list: [],
    isMore: false
  },
  onLoad: function (options) {
    var that = this
    that.request();
  },

  // 网络请求
  request: function () {
    var that = this
    wx.request({
      url: getApp().globalData.host + "&m=News&a=notice", //仅为示例，并非真实的接口地址
      data: {
        p: that.data.page
      },
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
      },
      success: function (res) {
        //请求成功
        if (res.data.status == 1) {
          console.log(res.data)
          Array.prototype.push.apply(that.data.list, res.data.list)
          console.log("拼接后")
          console.log(that.data.list)
          that.data.page++
          if (res.data.list.length == 0) {
            that.data.isMore = true
          } else {
            that.data.isMore = false
          }
          that.setData({
            isHide: true,
            list: that.data.list
          })
        } else {//请求失败
          wx.showToast({
            title: res.data.info,
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: "请求失败",
        })
      }
    })
  },
  onReachBottom: function () {
    var that = this;
    if (that.data.isMore) {
      that.request()
    }else{
      wx.showToast({
        title: '没有更多了',
      })
    }
  },
})